package org.squirrel.modules.bigscreen.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.squirrel.common.api.vo.Result;
import org.squirrel.common.system.base.controller.SquirrelController;
import org.squirrel.modules.bigscreen.dto.ReportShareDto;
import org.squirrel.modules.bigscreen.entity.ReportShare;
import org.squirrel.modules.bigscreen.service.ReportShareService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@Api(tags = "报表分享管理")
@RequestMapping("/reportShare")
public class ReportShareController extends SquirrelController< ReportShare, ReportShareService> {

    @Autowired
    private ReportShareService reportShareService;

    /**
     * 通过报表分享ID获得报表分享详情
     * 
     * @param id
     * @return
     */
    @ApiOperation(value = "通过报表分享ID获得报表分享详情", notes = "通过报表分享ID获得报表分享详情")
    @GetMapping({"/{id}"})
    public Result<?> detail(@PathVariable("id") Long id) {
    	try {
	        log.info("{}根据ID查询服务开始，id为：{}", this.getClass().getSimpleName(), id);
	        ReportShare result = reportShareService.getDetail(id);
	//        ReportShareDto dto = this.getDTO();
	//        GaeaBeanUtils.copyAndFormatter(result, dto);
	//        ResponseBean responseBean = this.responseSuccessWithData(this.resultDtoHandle(dto));
	//        log.info("{}根据ID查询结束，结果：{}", this.getClass().getSimpleName(), GaeaUtils.toJSONString(responseBean));
	        return Result.OK("通过报表分享ID获得报表分享详情成功", result);
    	}catch(Exception e) {
    		log.error("通过报表分享ID获得报表分享详情异常", e);
			return Result.error("通过报表分享ID获得报表分享详情失败,原因:" + e.getMessage());
    	}
    }

    /**
     * 通过报表分享编码获得报表分享详情
     * 
     * @param shareCode
     * @return
     */
    @ApiOperation(value = "通过报表分享编码获得报表分享详情", notes = "通过报表分享编码获得报表分享详情")
    @GetMapping({"/detailByCode"})
    public Result<?> detailByCode(@RequestParam("shareCode") String shareCode) {
    	try {
    		ReportShare result = reportShareService.detailByCode(shareCode);
    		return Result.OK("通过报表分享编码获得报表分享详情成功", result);
    	}catch(Exception e) {
    		log.error("通过报表分享编码获得报表分享详情异常", e);
			return Result.error("通过报表分享编码获得报表分享详情失败,原因:" + e.getMessage());
    	}
    }

    /**
     * 分享延期
     * 
     * @param dto
     * @return
     */
    @ApiOperation(value = "分享延期", notes = "分享延期")
    @PostMapping({"/shareDelay"})
    public Result<?> shareDelay(@RequestBody ReportShareDto dto) {
    	try {
	        reportShareService.shareDelay(dto);
	        return Result.OK("分享延期成功",dto);
    	}catch(Exception e) {
    		log.error("分享延期异常", e);
			return Result.error("分享延期失败,原因:" + e.getMessage());
    	}
    }

}
